package com.baitiaojun.video.timer;

import com.baitiaojun.video.feign.ElasticsearchVideoFeign;
import com.baitiaojun.video.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.List;

/**
 * @类名 VideoViewCountTimer
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/1/6 17:59
 * @版本 1.0
 */
@Slf4j
@Component
public class VideoViewCountTimer {

    @Autowired
    private VideoService videoService;

    @Autowired
    private ElasticsearchVideoFeign videoFeign;

    @Scheduled(initialDelay = 3000, fixedRate = 10000)
    public void updateVideoViewCount() {
        log.info("更新视频热度");
        List<Long> videoIds = videoService.getVideoIds();
        try {
            videoFeign.updateViewCount(videoIds);
        } catch (Exception e) {
            log.error("ElasticsearchVideoFeign服务异常");
        }
    }
}
